package com.dhsc.service.impl.yykh.yyzlkh;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhsc.domain.ywzx.yykh.yyzlkh.TbsxwhVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.domain.yypt.ResponseObject;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.yykh.yyzlkh.ITbsxwhDao;
import com.dhsc.service.yykh.yyzlkh.ITbsxwhService;
import com.dhsc.util.CommonUtil;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName TbsxwhServiceImpl
 * @description: 特别事项维护
 * @author: gx
 * @create: 2024-04-24 15:23:49
 **/
@Service
@Slf4j
public class TbsxwhServiceImpl implements ITbsxwhService {

    @Autowired
    private ITbsxwhDao tbsxwhDao;

    @Override
    public LayuiTableVo queryTbsxwh(TbsxwhVo tbsxwhVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(tbsxwhVo.getPage(), tbsxwhVo.getLimit());
            List<TbsxwhVo> list = tbsxwhDao.queryTbsxwh(tbsxwhVo);
            PageInfo<TbsxwhVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询特别事项维护信息出错",e);
            throw new MyException("查询特别事项维护信息出错");
        }
        return obj;
    }

    @Override
    public ResponseObject saveTbsxwh(TbsxwhVo tbsxwhVo) {
        ResponseObject obj = new ResponseObject();
        try {
            if (CommonUtil.isNotEmptyObj(tbsxwhVo.getBh())){
                tbsxwhDao.updateTbsxwh(tbsxwhVo);
            }else{
                tbsxwhDao.insertTbsxwh(tbsxwhVo);
            }

            obj.setStatus(200);
        }catch (Exception e){
            log.error("更新特别事项维护出错",e);
            throw new MyException("更新特别事项维护出错");
        }
        return obj;
    }

    @Override
    public ResponseObject deleteTbsxwh(TbsxwhVo tbsxwhVo) {
        ResponseObject obj = new ResponseObject();
        try {
        	tbsxwhDao.deleteTbsxwh(tbsxwhVo);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("删除特别事项维护出错",e);
            throw new MyException("删除特别事项维护出错");
        }
        return obj;
    }
}
